#include "threadpool.h"
#include <QDebug>

ThreadPool::ThreadPool(int maxThreads, QObject *parent)
    : QObject(parent) {
    m_pool = QThreadPool::globalInstance();
    m_pool->setMaxThreadCount(maxThreads);
}

ThreadPool::~ThreadPool() {
    m_pool->waitForDone();
}

void ThreadPool::start(QRunnable *runnable) {
    m_pool->start(runnable);
}

void ThreadPool::setMaxThreadCount(int maxThreads) {
    m_pool->setMaxThreadCount(maxThreads > 0 ? maxThreads : QThread::idealThreadCount());
}

int ThreadPool::activeThreadCount() const {
    return m_pool->activeThreadCount();
}

int ThreadPool::maxThreadCount() const {
    return m_pool->maxThreadCount();
}

void ThreadPoolWorker::run()
{
    QTextStream(stdout) << "---------run-------------\n";
}
